// import vue from "vue"

export default {
	data: () => {
		return {
			clearAutocompleteListTimeStatus: null,
			AutocompleteList: [],
			searchScrollTop: 0,
			oldSearchScroll: {
				scrollTop: 0
			},
			showClearIcon: false
		}
	},
	methods: {
		clearAutocompleteList() {
			const _self = this
			_self.clearAutocompleteListTimeStatus = setTimeout(() => {
				_self.AutocompleteList = []
			}, 300)
		},
		clearListTimeStatus() {
			clearTimeout(this.clearAutocompleteListTimeStatus)
		},
		getAutocompleteList() {
			if (this.keyword.length < 2) {
				this.AutocompleteList = [];
				return false;
			}
			// let data = this.initNewData();
			// data.from = 4038;
			// data.location = 4050;
			// data.keyword = keywords;
			// uni.request({
			// 	url: this.baseConfig.serverURL + 'zhaobiao/SearchAutoCompleteKwdsHandler.ashx',
			// 	data: data,
			// 	method: "POST",
			// 	header: {
			// 		"content-type": "application/x-www-form-urlencoded" //"application/json"
			// 	},
			// 	success: (res) => {
			// 		if (res.statusCode == 200) {
			// 			if (res.data.ret) {
			// 				//获取成功，绑定
			// 				let list = res.data.other2.data;
			// 				if (list && list.length > 0) {
			// 					this.AutocompleteList = list;
			// 					this.searchScrollTop = this.oldSearchScroll.scrollTop
			// 					this.$nextTick(() => {
			// 						this.searchScrollTop = 0
			// 					});
			// 				}
			// 			} else {
			// 				this.AutocompleteList = [];
			// 			}
			// 		} else {
			// 			this.AutocompleteList = [];
			// 		}
			// 	},
			// 	fail: (res) => {
			// 		this.AutocompleteList = [];
			// 	}
			// });
			if (this.comtype === 2) {
				uni.$u.http
					.post('/shuju/shujudaochu/SearchAutoCompleteKwdsHandler.ashx', {
						location: this.location,
						keyword: uni.$u.trim(this.keyword),
					})
					.then(rs => {
						this.AutocompleteList = rs.data
						this.searchScrollTop = this.oldSearchScroll.scrollTop
						this.$nextTick(() => {
							this.searchScrollTop = 0
						});
						// console.log(1,this.autolist)
					}).catch(err => {
						// 不提示toast
						// uni.$u.toast(err.msg || '服务器异常！');
					});
			} else {
				// 按名称，同企情分析中的搜索下拉
				uni.$u.http
					.post('/shuju/fenxi/company/SearchCompanyAutoCompleteHandler.ashx', {
						location: this.location,
						company: uni.$u.trim(this.keyword),
						// 业主：3   供应：2   代理5
						lytype: this.comtype === 2 ? 3 : 2
					})
					.then(rs => {
						const arr = []
						rs.data.map(item => {
							arr.push({
								title: item.company
							})
						})
						this.AutocompleteList = arr
						this.searchScrollTop = this.oldSearchScroll.scrollTop
						this.$nextTick(() => {
							this.searchScrollTop = 0
						});
						// console.log(1,this.autolist)
					}).catch(err => {
						// 不提示toast
						// uni.$u.toast(err.msg || '服务器异常！');
					});
			}
		},
		Completeheighthtml(key, cont) {
			if (key === '') {
				return cont;
			}
			var keyarr = key.split(',');
			for (var i = 0; i < keyarr.length; i++) {
				if (keyarr[i] != '') {
					var reg = new RegExp((`(${keyarr[i]})`), "gm");
					var replace = '<text style="color:red;font-weight: bold;" >$1</text>';
					cont = cont.replace(reg, replace)
				}
			}
			return cont;
		},
		searchScroll: function(e) {
			this.oldSearchScroll.scrollTop = e.detail.scrollTop
		},
		clearList() {
			uni.hideKeyboard();
			this.AutocompleteList = [];
		}
	}
}